import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:date_format/date_format.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:verse_systems/res/colors.dart';
import 'package:verse_systems/widgets/sp_button.dart';


typedef ResultBlock = void Function(String result);
class ChooseDataPicker extends StatefulWidget {
  final ResultBlock onResult;
  const ChooseDataPicker({super.key, required this.onResult});

  @override
  State<ChooseDataPicker> createState() => _ChooseDataPickerState();
}

class _ChooseDataPickerState extends State<ChooseDataPicker> {
  String timeStr = "";

  @override
  Widget build(BuildContext context) {
    return Material(
      child: SizedBox(
      height: 400.w,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        // mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Container(
            height: 60.w,
            decoration: BoxDecoration(
              border: Border(
                  bottom: BorderSide(
                      color: Colors.grey.withOpacity(0.1), width: 1)),
            ),
            child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Container(
                    margin: EdgeInsets.only(left: 25.w),
                    width: 95.w,
                    child: SPButton(
                      minHeight: 35.w,
                      fontSize: 13.sp,
                      text: 'cancel'.tr,
                      textColor: Colours.app_main_background_color,
                      radius: 17.5.w,
                      side: const BorderSide(
                        color: Colours.app_main_background_color,
                        width: 1.0,
                      ),
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(right: 25.w),
                    width: 95.w,
                    child: SPButton(
                      minHeight: 35.w,
                      fontSize: 13.sp,
                      text: "confirm".tr,
                      textColor: Colours.app_main_color,
                      backgroundColor: Colours.app_main_background_color,
                      radius: 17.5.w,
                      onPressed: () async {
                        Navigator.of(context).pop();
                        widget.onResult(timeStr);
                      },
                    ),
                  ),
                ]),
          ),
          Expanded(
            child: Localizations(
                locale: const Locale('zh'),
                delegates: const [
                  GlobalMaterialLocalizations.delegate,
                  GlobalWidgetsLocalizations.delegate,
                  GlobalCupertinoLocalizations.delegate,
                ],
                child: CupertinoDatePicker(
                  dateOrder: DatePickerDateOrder.ymd,
                  mode: CupertinoDatePickerMode.date,
                  initialDateTime: DateTime.now(),
                  onDateTimeChanged: (date) {
                    timeStr = formatDate(date, [yyyy, '-', mm, '-', dd]);
                    debugPrint("timeStr--$timeStr");
                  },
                )),
          )
        ],
      )),
    );
  }
}
